<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>异常处理经典小案例</title>
	</head>

	<body>

		<h2>你可以输入：16,1,6 等试试</h2>
		<p>请输入 5 和 10 之间的一个数:</p>

		<input id="demo" type="text">
		<button type="button" onclick="myFunction()">检测输入</button>
		<p id="message"></p>

		<script>
			function myFunction() {
				var message, x;
				message = document.getElementById("message");
				message.innerHTML = "";
				x = document.getElementById("demo").value;
				try {
					if(x == "") throw "为空";
					if(isNaN(x)) throw "不是一个数字";
					if(x > 10) throw "太大了";
					if(x < 5) throw "太小了";
				} catch(err) {
					message.innerHTML = "输入的值 " + err;
				}
			}
		</script>

	</body>

</html>